const text = '这是一段文本';

/**
 * 浏览器环境下
 */
// base64编码
let ciphertext = btoa(String.fromCharCode(...new TextEncoder(text).encode(text)));
// base64解码
let plaintext = new TextDecoder().decode(Uint8Array.from(atob(ciphertext), (e)=>e.charCodeAt(0)));

/**
 * node.js环境下
 */
// base64编码
ciphertext = Buffer.from(text).toString('base64');
// base64解码
plaintext = Buffer.from(ciphertext, 'base64').toString();